package org.example.orderservice.service;

import lombok.RequiredArgsConstructor;
import org.example.orderservice.dao.OrderEntity;
import org.example.orderservice.dao.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrderService {

    @Autowired
    private OrderRepository repository;

    @Transactional(rollbackFor = Exception.class)
    public OrderEntity createOrder(String userId, String commodityCode, int count, int money){
        OrderEntity order = new OrderEntity();
        order.setUserId(userId);
        order.setCommodityCode(commodityCode);
        order.setCount(count);
        order.setMoney(money);
        return repository.save(order);
    }
}